﻿@* Generator: Template TypeVisibility: Internal GeneratePrettyNames: True *@
@using System
@using System.Collections.Generic
@using Hangfire.Dashboard
@using Hangfire.Dashboard.Pages
@using Hangfire.Dashboard.Resources
@using Hangfire.Storage
@using Newtonsoft.Json
@inherits RazorPage
@{
    Layout = new LayoutPage(Strings.HomePage_Title);
    IDictionary<DateTime, long> succeeded = null;
    IDictionary<DateTime, long> failed = null;
    IDictionary<DateTime, long> deleted = null;

    var period = Query("period") ?? "day";

    var monitor = Storage.GetMonitoringApi();
    if ("week".Equals(period, StringComparison.OrdinalIgnoreCase))
    {
        succeeded = monitor.SucceededByDatesCount();
        failed = monitor.FailedByDatesCount();
        if (monitor is JobStorageMonitor jobStorageMonitor)
        {
            deleted = jobStorageMonitor.DeletedByDatesCount();
        }
    }
    else if ("day".Equals(period, StringComparison.OrdinalIgnoreCase))
    {
        succeeded = monitor.HourlySucceededJobs();
        failed = monitor.HourlyFailedJobs();
        if (monitor is JobStorageMonitor jobStorageMonitor)
        {
            deleted = jobStorageMonitor.HourlyDeletedJobs();
        }
    }
}

<div class="row">
    <div class="col-md-12">
        <h1 class="page-header">@Strings.HomePage_Title</h1>
        @if (Metrics.Count > 0)
        {
            <div class="row">
                @foreach (var metric in Metrics)
                {
                    <div class="col-md-2">
                        @Html.BlockMetric(metric)
                    </div>
                }
            </div>
        }
        <h3>@Strings.HomePage_RealtimeGraph</h3>
        <canvas width="1140" height="250" id="realtimeGraph" data-succeeded="@Statistics.Succeeded" data-failed="@Statistics.Failed" data-deleted="@Statistics.Deleted"
             data-succeeded-string="@Strings.HomePage_GraphHover_Succeeded"
             data-failed-string="@Strings.HomePage_GraphHover_Failed"
             data-deleted-string="@Strings.JobsSidebarMenu_Deleted"></canvas>
        <div class="display-none">
            <span data-metric="succeeded:count"></span>
            <span data-metric="failed:count"></span>
            <span data-metric="deleted:count"></span>
        </div>

        <h3>
            <div class="btn-group pull-right margin-top-2p">
                <a href="?period=day" class="btn btn-sm btn-default @("day".Equals(period, StringComparison.OrdinalIgnoreCase) ? "active" : null)">@Strings.Common_PeriodDay</a>
                <a href="?period=week" class="btn btn-sm btn-default @("week".Equals(period, StringComparison.OrdinalIgnoreCase) ? "active" : null)">@Strings.Common_PeriodWeek</a>
            </div>
            @Strings.HomePage_HistoryGraph
        </h3>

        @if (succeeded != null && failed != null)
        {
            <canvas width="1140" height="250" id="historyGraph"
                 data-succeeded="@JsonConvert.SerializeObject(succeeded)"
                 data-failed="@JsonConvert.SerializeObject(failed)"
                 data-deleted="@(deleted != null ? JsonConvert.SerializeObject(deleted) : String.Empty)"
                 data-succeeded-string="@Strings.HomePage_GraphHover_Succeeded"
                 data-failed-string="@Strings.HomePage_GraphHover_Failed"
                 data-deleted-string="@Strings.JobsSidebarMenu_Deleted"
                 data-period="@period">
            </canvas>
        }
    </div>
</div>